package sysAuth

import initConfig.SysInitData
import sysUtil.SysCommUtil

class SysFunctions {

    //菜单权限控制
    String funcNo;
    String funcName;
    String path;
    String marks;
    Long parentId;
    Long orderNum; //设置菜单级别，目前就设置4级吧，多了就没啥意思了。
    Long rptId = -1; //预留配置报表ID
    String icon ; //图标
    String script;//脚本
    String state = "1" //是否在用
    String operations ="detail"
    String mobile = "0"

    String creator ;//操作人
    String updater;//最近一次更新人
    Date dateCreated;
    Date lastUpdated;

    static constraints = {
        funcNo(nullable: false,blank: false,unique: true )
        funcName(nullable: false )
        path(nullable: true)
        marks(nullable: true)
        parentId(nullable: true)
        orderNum(nullable: true) //设置菜单级别，目前就设置4级吧，多了就没啥意思了。
        rptId(nullable: true) //预留配置报表ID
        icon(nullable: true)
        script(nullable: true)
        creator(nullable: false)
        updater(nullable: true)
        state(nullable: false )
    }
    static mapping = {
        version false
    }

    public Map getMap(){
        ["id":this.id,"funcNo":this.funcNo,funcName:this.funcName,
         orderNum:this.orderNum,path:this.path,parentId: this.parentId,
         icon:this.icon,rptId:this.rptId,marks:this.marks,creator: this.creator,
         script:this.script ]
    }

    static init(){
        //系统默认菜单
        //系统一级菜单
        if(SysFunctions.count() ==0){

            def sysSet = new SysFunctions(funcNo: "SYS_SET",funcName: "系统管理",path:null,orderNum:0,parentId:null,icon:"layui-icon-set-sm" ,creator: SysInitData.SYS_ADMIN)
            sysSet.save(flush: true)

            def Grade2Function = [[funcNo:"SYS_USER",funcName:"用户管理",orderNum:1,parentId: sysSet.id,path:"reportAdmin/userList.html", icon:"layui-icon-user",creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_FUNC",funcName:"功能管理",orderNum:2,parentId: sysSet.id,path:"reportAdmin/function.html", icon:"layui-icon-template",creator: SysInitData.SYS_ADMIN ],
                                  [funcNo:"SYS_DATA",funcName:"数据管理",orderNum:3,parentId: sysSet.id,path:"reportAdmin/data.html", icon:"layui-icon-table" ,creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_DEPT",funcName:"部门管理",orderNum:3,parentId: sysSet.id,path:"reportAdmin/department.html", icon:"layui-icon-table" ,creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_ROLE",funcName:"角色管理",orderNum:4,parentId: sysSet.id,path:"reportAdmin/roleList.html", icon:"layui-icon-templeate-1",creator: SysInitData.SYS_ADMIN ],
                                  [funcNo:"SYS_CFG",funcName:"系统配置",orderNum:7,parentId: sysSet.id,path:"reportAdmin/sysViewCfg.html", icon:"layui-icon-util",creator: SysInitData.SYS_ADMIN ],
                                  [funcNo:"SYS_OPERATE",funcName:"操作管理",orderNum:7,parentId: sysSet.id,path:"reportAdmin/operation.html", icon:"layui-icon-form" ,creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_ICON",funcName:"图标管理",orderNum:8,parentId: null,path:"reportAdmin/unicode.html",icon:"layui-icon-face-smile",creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_SOURCE",funcName:"数据源管理 ",orderNum:8,parentId: sysSet.id,path:"reportAdmin/dataSource.html",icon:"layui-icon-face-smile",creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_NOTICE",funcName:"消息中心 ",orderNum:10,parentId: null,path:"reportAdmin/sysNotice.html",icon:"layui-icon-notice",creator: SysInitData.SYS_ADMIN],
                                  [funcNo:"SYS_PARAMS",funcName:"参数管理 ",orderNum:11,parentId: sysSet.id,path:"reportAdmin/sysParams.html",icon:"layui-icon-notice",creator: SysInitData.SYS_ADMIN]
            ]

            Grade2Function.each {
                new SysFunctions(funcNo:it.funcNo,funcName:it.funcName,orderNum:it.orderNum,parentId: it.parentId,path:it.path, icon:it.icon,creator: it.creator).save(flush: true)
            }

            //----------模块2
            sysSet = new SysFunctions(funcNo: "SYS_WIDGET",funcName: "Report模块",path:null,orderNum:0,parentId:null,icon:"layui-icon-set-sm" ,creator: SysInitData.SYS_ADMIN)
            sysSet.save(flush: true)

            Grade2Function = [[funcNo:"SYS_WIDGET1",funcName:"Widget设计",orderNum:1,parentId: sysSet.id,path:"xdWidget/xdWidget.html", icon:"layui-icon-user",creator: SysInitData.SYS_ADMIN],
                              [funcNo:"SYS_WIDGET2",funcName:"Form元素设计",orderNum:2,parentId: sysSet.id,path:"xdWidget/condition.html", icon:"layui-icon-template",creator: SysInitData.SYS_ADMIN ],
                              [funcNo:"SYS_WIDGET3",funcName:"Panel设计",orderNum:3,parentId: sysSet.id,path:"xdWidget/panel.html",icon:"layui-icon-face-smile",creator: SysInitData.SYS_ADMIN],
                              [funcNo:"SYS_WIDGET4",funcName:"Report设计",orderNum:4,parentId: sysSet.id,path:"xdWidget/xdWidgetReport.html", icon:"layui-icon-table" ,creator: SysInitData.SYS_ADMIN],
            ]

            Grade2Function.each {
                new SysFunctions(funcNo:it.funcNo,funcName:it.funcName,orderNum:it.orderNum,parentId: it.parentId,path:it.path, icon:it.icon,creator: it.creator).save(flush: true)
            }
            //----------end 模块2
        }

    }

}
